home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / slang.txt < prev    next >
Text File  |  1994-10-29  |  8KB  |  193 lines

  1. /*
  2. █████████████████████████████████████████████████████████████████████████████
  3. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ KNOW-HOW.SLANG ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5. ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  6. █████████████████████████████████████████████████████████████████████████████
  7.  
  8. This text contain complete description of KNOW_HOW.SLANG 5.0x, the
  9. product in the 5th version of library. It provide the following features:
  10.     a. BASIC-like language which could be used for calculators, spreadsheets,
  11.        or as a language of the integrated package.
  12.     b. Slang class child classes could have additional functions and
  13.        work with functions of concrete program.
  14.  
  15. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  16. Example:
  17. Additional (and very powerfull) features are available if KNOW-HOW.SLANG
  18. is used together with KNOW-HOW.GRAPHICS.
  19. SLANG is BASIC-like language, designed as CPP class. Its child classes could
  20. have additional operators, so KNOW-HOW.SLANG.GRAPHICS is the BASIC with
  21. access to drawing tools of current product. It provide to user the
  22. possibility to load graphical resourses (DOS or Windows, or other if he add
  23. some code) and interprete them in run-time. There are very many applications
  24. of this tool, like run-time changeable GUI, maketing (without stage of
  25. compilation, KNOW-HOW.VECTOR is the ready-to-use product of this type) of BGI,
  26. GDI and so on applications, vector drawing tools. Together with
  27. BASIC math. functions it could also be used for data plotting, spreadsheets
  28. and so on.
  29.  
  30. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  31. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ RULES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  32. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  33.  
  34. 1. 3 types are supported: REAL, STRING and ARRAY (of REAL). Assignment
  35.    could not change the type of variable:
  36.    x = 3
  37.    y = 4
  38.    x = y           (OK)
  39.  
  40.    x = "Hello"
  41.    y = x           (OK)
  42.  
  43.    x = "Hello"
  44.    y = 3
  45.    y = x           (Error)
  46.  
  47.    The array variable must be declared:
  48.    x = 3.5
  49.    MY_ARRAY[12+x];
  50.    Semicolon is necessary to end the declaration. 'x' in this case will be
  51.    rounded down.
  52.    After the initialization array could be used:
  53.    y = MY_ARRAY[12] + 3.21
  54.    Numeration begins from 1 to array dimention, MY_ARRAY[0] contains
  55.    dimention of the array.
  56. 2. There are the following language constructions:
  57.    a) FOR i = ... TO ...
  58.       ...
  59.       NEXT
  60.    b) !label_name
  61.       ...
  62.       GOTO label_name
  63.    c) IF <condition> THEN ... (othervise go to next line)
  64.    d) Subroutines names should begin from '@':
  65.       @SUB(a, b, "Hi")
  66.      ....
  67.       RETURN (or RETURN REAL or STRING)
  68.    e) Main part of the program should be finished by the END operator.
  69.    f) PLAY("filename") pass the control to the main (END-terminated) routine
  70.       in the external file. Functions of the previous file(s) are not
  71.       available, but variables still are.
  72.    g) There are two types of remarks : & means remark to the end of the line
  73.       and /* * / remarks the whole block.
  74.    h) "Rudimental" Basic functions PRINT and INPUT are still supposed,
  75.       user could use overloaded versions.
  76.       PRINT 5, 7, "Hi"; x, y;
  77.       INPUT "input x: ", x
  78.       ',' is used for listing, ';' begin new line.
  79.    i) PAUSE(msec) suspends the program for given period.
  80.    j) SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, LOG, LG are the set of
  81.       math. functions of SLANG
  82.    h) DELETE <name> delete variable and release name.
  83. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  84. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ FILES ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  85. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  86. ▐▐▐▐▐▐▐ File SLANGTAB.H contains language names and messages.
  87.  
  88. enum { DELIMITER = 1,     // '\0'(end),/*,*/,\r,<>=,' ',+-^/*%=;(),<>[]
  89.        VARIABLE,          // Symbolic name of variable, like x, k1 and so on
  90.        NUMBER,            // Double value
  91.        COMMAND,           // See "commands TABLE[]" later in this file
  92.        STRING,            // Remarked blocks or quoted text
  93.        QUOTE,             // Quote
  94.        ALPHA };           // @ (gosub) or ! (label) symbol
  95.  
  96.  
  97. enum { IF = 1, THEN, FOR, NEXT, TO, GOTO, EOL, DELETE,
  98.        FINISHED, GOSUB, LABEL, PLAYEX, RETURN, END, REMARK,
  99.        REMARK_BLOCK,
  100.        SIN, COS, TAN, ASIN, ACOS, ATAN, ABS, EXP, LOG, LG,
  101.        PRINT, INPUT, PAUSE,
  102.  
  103.        USER };  // All functions after this are user-defined in Slang childs
  104.  
  105. struct commands
  106.     {
  107.     char command[20];
  108.     char tok;
  109.     };
  110.  
  111. static commands TABLE[] =  {
  112.         { "if",     IF       },
  113.         ......................
  114. #include "userlang.inc"
  115.         { "",       END      }     // Marker of end of the table
  116.         };
  117.  
  118.  
  119. static char* error_string[] =
  120.     {
  121.     "Syntax error",                            //  0
  122.     "Symbol '(' or ')' expected",              //  1
  123.     ................................................
  124.     "USER ERROR"
  125.     };
  126.  
  127. Put the special attention to the line
  128. #include "userlang.inc"
  129. This trick is used to expand the list of SLANG functions and add user-defined
  130. ones, which are used by Slang child classes.
  131. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  132. ▐▐▐▐▐▐▐ Files VARIABLE.*, VAR_TAB.* contains descriptions of the variables
  133. of 3 base types, and the VarTable class - table of variables.
  134. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  135. ▐▐▐▐▐▐▐ Files SLANG.H, SLANG.CPP and BASICA.CPP contains language itself.
  136. It is recursive interpreter. The most important (for user) functions of
  137. Slang class:
  138.     void set_error(int err) { error = err; }
  139.     int get_error() { return error; }
  140. "error" is the number of Slang error (listed in SLANGTAB.H). For
  141. compatibility I don't use templates, so almost every function should do its
  142. own error-checking.
  143.     void set_program(char* p) { program = p; }
  144.     char* load_program(char*); // Remove old program and load new file
  145. "program" is the text loaded from file
  146.     void print();              // General output function
  147.     void input();              // General input function
  148. PRINT and INPUT are rudimental functions. Some of the Slang childs could
  149. use another output routines, like outtextxy() and so on.
  150.     void basic(char*);         // Executes program pointed by char*
  151. General routine
  152.     void play();               // Play external file
  153.     virtual void error_report(char* text); // Overload for your own print
  154.     virtual void terminate();  // User-defined terminator (ESC and so on)
  155. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  156. «»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«»«
  157. -----------------------------------------------------------------------------
  158. Example.
  159.  
  160. #include <conio.h>     // only for interruption on key pressed **************
  161. class Demo : public Slang
  162.     {
  163.     virtual void terminate();  // User-defined terminator (ESC and so on)
  164.     };
  165. /////////////
  166. void Demo::terminate()
  167.     {
  168.     if(kbhit())
  169.     {
  170.     getch();
  171.     if(kbhit())
  172.         getch();
  173.     serror(23);
  174.     }
  175.     }
  176. ///////////////////////////////////////////////////////////////////////////
  177. void main()
  178.     {
  179.     Demo* basic = new Demo();
  180.     basic->basic(basic->load_program("work.bas"));
  181.     delete basic;
  182.     printf("%s", "\n");
  183.     }
  184.  
  185. Another way of Slang usage - not to call Slang from your program,
  186. but organize your program as a Slang program, which sometimes could
  187. include user to dialog using INPUT and other Slang base operations, but
  188. usually simply call user's functions, including dialog modules, not
  189. terminating program execution.
  190.  
  191.  
  192.  
  193.